import {reqArticleType, reqArticleList, reqArticleListType, reqArticleDetail} from '../../../api'
import * as constants from './constants'

const updateArticleType = (typeData) => ({
    type: constants.UPDATE_TYPE_DATA,
    typeData
});

export const getArticleType = (callback) => {
    return async (dispatch) => {
        // dispatch(updateLoading(true));
        const result = await reqArticleType();
        // dispatch(updateLoading(false));
        if (result.code === 0) {
            dispatch(updateArticleType(result.data));
            if (callback != null) {
                callback(result.data);
            }
        }
    }
};

export const getArticleList = (body, func) => {
    return async (dispatch) => {
        // dispatch(updateLoading(true));
        const result = await reqArticleList(body);
        // dispatch(updateLoading(false));
        if (result.code === 0) {
            func(result.data);
        }
    }
};

export const getArticleListType = (body, func) => {
    return async (dispatch) => {
        // dispatch(updateLoading(true));
        const result = await reqArticleListType(body);
        // dispatch(updateLoading(false));
        if (result.code === 0) {
            func(result.data);
        }
    }
};

export const getArticleDetail = (body, func) => {
    return async (dispatch) => {
        // dispatch(updateLoading(true));
        const result = await reqArticleDetail(body);
        // dispatch(updateLoading(false));
        if (result.code === 0) {
            func(result.data);
        }
    }
};